//
//  HZOrderConfirmHeaderView.m
//  app
//
//  Created by 刘华舟 on 15/5/6.
//  Copyright (c) 2015年 hdaren. All rights reserved.
//

#import "HZOrderConfirmHeaderView.h"


#import "HZImageSourceConstant.h"


static const CGFloat kOrderConfirmLabelHeight = 24;

static const NSInteger kOrderConfirmConfirmWidth = 200;
static const CGFloat kOrderConfirmVConfirmHeight = 40;

@interface HZOrderConfirmHeaderView()

@property (strong, nonatomic) UILabel* goodsCountLabel;
@property (strong, nonatomic) UILabel *transformMoneyLabel;
@property (strong, nonatomic) UILabel *totalMoneyLabel;


@property (strong, nonatomic) UIButton *confirmBtn;



@end

@implementation HZOrderConfirmHeaderView

- (void)drawRect:(CGRect)rect{
    [self drawBackground:self.bounds color:HZ_WHITE_COLOR];
    [self drawHorizonLineLeft:[self.ubo uw:0] right:[self.ubo uw:0] at:[self.ubo fy:UB_TOP py:1] color:HZ_MALL_M_SEPARATOR_CELL_LINE];
}

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        self.ufo.height = [self.ubo oh:kOrderConfirmHeaderViewHeight];
        self.backgroundColor = HZ_WHITE_COLOR;
        self.contentMode = UIViewContentModeCenter;
        
        //添加总件说
        self.goodsCountLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.ubo fx:UB_LEFT ux:kSizeMallViewMargin fy:UB_TOP oy:kSizeMallViewMargin/4],
                                                                           [self.ubo fw:UB_HALF uw:-2*kSizeMallViewMargin oh:kOrderConfirmLabelHeight/2])];
        self.goodsCountLabel.textAlignment = NSTextAlignmentLeft;
        self.goodsCountLabel.textColor = HZ_MALL_TEXT_GRAY_COLOR;
        self.goodsCountLabel.font = kHZFont_Content_S;
        self.goodsCountLabel.backgroundColor = HZ_CLEAR_COLOR;
        [self addSubview:self.goodsCountLabel];
        
        
        
        //添加运费
        self.transformMoneyLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.goodsCountLabel.ufo fx:UB_LEFT fy:UB_BOTTOM oy:kSizeMallViewMargin/4],
                                                                           [self.goodsCountLabel.ubo fw:UB_WIDTH fh:UB_HEIGHT])];
        self.transformMoneyLabel.textAlignment = NSTextAlignmentLeft;
        self.transformMoneyLabel.textColor = HZ_MALL_TEXT_GRAY_COLOR;
        self.transformMoneyLabel.font = kHZFont_Content_S;
        self.transformMoneyLabel.backgroundColor = HZ_CLEAR_COLOR;
        [self addSubview:self.transformMoneyLabel];
        
        //添加金额总计
        self.totalMoneyLabel = [[UILabel alloc] initWithFrame:CGRectOf([self.transformMoneyLabel.ufo fx:UB_LEFT fy:UB_BOTTOM oy:kSizeMallViewMargin/4],
                                                                       [self.goodsCountLabel.ubo fw:UB_WIDTH fh:UB_HEIGHT*2])];
        self.totalMoneyLabel.textAlignment = NSTextAlignmentLeft;
        self.totalMoneyLabel.textColor = HZ_RED_COLOR;
        self.totalMoneyLabel.font = kHZFont_TitleBar_M;
        self.totalMoneyLabel.backgroundColor = HZ_CLEAR_COLOR;
        [self addSubview:self.totalMoneyLabel];
        
        
        

        
        //确认下单按钮
  
        self.confirmBtn = [[UIButton alloc] initWithFrame:CGRectOf([self.ubo fx:UB_RIGHT ux:-(kOrderConfirmConfirmWidth+kSizeMallViewMargin) fy:UB_TOP oy:(kOrderConfirmHeaderViewHeight-kOrderConfirmVConfirmHeight)/2],
                                                                        [self.ubo uw:kOrderConfirmConfirmWidth oh:kOrderConfirmVConfirmHeight])];
        
        [self.confirmBtn setBackgroundColor:HZ_MALL_MAIN_THEME_RED];
        [self.confirmBtn.titleLabel setFont:kHZFont_TitleBar_S];
        [self.confirmBtn setTitle:@"提交订单" forState:UIControlStateNormal];
        [self.confirmBtn setTitleColor:HZ_WHITE_COLOR forState:UIControlStateNormal];
        [self.confirmBtn addTarget:self action:@selector(confirmBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:self.confirmBtn];
        
    }
    return self;
}


//刷新计价面板
- (void)refreshCountPanelWithNum:(NSString *)num postage:(NSString *)postate money:(NSString *)money{
    self.goodsCountLabel.text = [NSString stringWithFormat:@"共%@件", num];
    self.transformMoneyLabel.text = [NSString stringWithFormat:@"配送运费:￥%@", postate];
    self.totalMoneyLabel.text = [NSString stringWithFormat:@"合   计:￥%@", money];
}


//点击确认下单
- (void)confirmBtnOnClick{
    if(self.targetCallerConfirm){
        [self.targetCallerConfirm call];
    }
}

@end
